<?php
/**
 * PHP Framework Integration SOAP Web Service Reference class
 *
 * @author Andrew <andrew@vitche.com>
 * @author Frozen Rain <frozenrain@mail.ru>
 **/

class SOAPWebServiceReference extends WebServiceReference {

    private $_proxyHost = null;

    private $_proxyPort = null;

    public function __construct($uri) {

        parent::__construct($uri);
    }

    public function execute($method, $arguments) {

        $this->_proxyHost = Configuration::get("Framework.Integration.SOAPWebService.SOAPWebServiceReference._proxyHost");
        $this->_proxyPort = Configuration::get("Framework.Integration.SOAPWebService.SOAPWebServiceReference._proxyPort");

        $settings = array();

        if (isset($this->_proxyHost)) {
            $settings['proxy_host'] = $this->_proxyHost;
        }

        if (isset($this->_proxyPort)) {
            $settings['proxy_port'] = $this->_proxyPort;
        }

        $soapClient = new SoapClient($this->_uri, $settings);
        $timeStart = microtime(TRUE);
        $response = $soapClient->$method($arguments);
        $timeInterval = microtime(TRUE) - $timeStart;
        Trace::writeLine("SOAPWebServiceReference::execute($method, ...) took $timeInterval");
        $method .= "Result";
        return SOAPSerializer::fromResult($response->$method);
    }
}
?>